<?php

include_once '../global-includes.php';
include_once 'rss-functions.php';

$handler = RssHandler::getInstance();

$xml_parser = xml_parser_create();

$channel = 1; //tmp (NEWS CHANNEL)

xml_set_element_handler($xml_parser, "startElement", "endElement"); 
xml_set_character_data_handler($xml_parser, "characterData"); 

$fp = fopen("http://news.finance.ua/ua/rss","r") or die("Error reading RSS data."); 

while ($data = fread($fp, 4096)) 
   xml_parse($xml_parser, $data, feof($fp)) or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); 

fclose($fp);
xml_parser_free($xml_parser);


$dbHandler = DBHandler::getInstance();

foreach ($handler->getData() as $key => $value){
	$value['cid'] = $channel;
 	$dbHandler->executeINSERTQuery('rss_import', $value);
 }
		

echo 'done!';

?>